// Created by wangliang on 2025/2/14.
import 'package:flutter/material.dart';
import 'package:fluttertoast/fluttertoast.dart';

class ToastUtil {
  static void showNativeToast(String message,
      {Toast duration = Toast.LENGTH_SHORT}) {
    Fluttertoast.showToast(
      msg: message,
      toastLength: duration,
      gravity: ToastGravity.BOTTOM,
      timeInSecForIosWeb: 1,
      backgroundColor: Colors.black.withOpacity(0.8),
      textColor: Colors.white,
      fontSize: 16.0,
    );
  }

  static FToast? _fToast;

  static showToast(BuildContext context, String content) {
    Widget toast = Container(
      padding: const EdgeInsets.symmetric(horizontal: 24.0, vertical: 12.0),
      decoration: BoxDecoration(
        borderRadius: BorderRadius.circular(25.0),
        color: Colors.black.withOpacity(0.8),
      ),
      child: Text(
        content,
        style: const TextStyle(color: Colors.white),
      ),
    );
    _fToast?.removeCustomToast();
    _fToast ??= FToast();
    _fToast?.init(context).showToast(
        child: toast,
        gravity: ToastGravity.BOTTOM,
        toastDuration: const Duration(seconds: 2));
  }
}
